//
//  aggregation.hpp
//  learnC++
//
//  Created by liuzhibing on 2018/6/10.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#ifndef aggregation_hpp
#define aggregation_hpp

#include <stdio.h>
#include <iostream>

//聚合
class Teacher
{
private:
    std::string m_name;
    
public:
    Teacher(std::string name)
    : m_name(name)
    {
    }
    
    std::string getName() { return m_name; }
};

class Department
{
private:
    Teacher *m_teacher; // This dept holds only one teacher for simplicity, but it could hold many teachers
    
public:
    Department(Teacher *teacher = nullptr)
    : m_teacher(teacher)
    {
    }
};

/*
 部门的销毁不会影响教师
 // Create a teacher outside the scope of the Department
 
 Teacher *teacher = new Teacher("Bob"); // create a teacher
 {
 // Create a department and use the constructor parameter to pass
 // the teacher to it.
 
 Department dept(teacher);
 
 } // dept goes out of scope here and is destroyed
 
 // Teacher still exists here because dept did not delete m_teacher
 
 std::cout << teacher->getName() << " still exists!";
 
 delete teacher;
 
 */


#endif /* aggregation_hpp */
